﻿package model.drawPanel.entitys;
import java.io.Serializable;
import java.util.Vector;

import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Display;

/*
 */
public	abstract class Entity implements Serializable{
  /**
	 * 
	 */
	private static final long serialVersionUID = 101250100L;
  protected int id;
  protected  transient Color color;
  protected  int width;//粗细宽度

  protected  int style;//实线，点线，虚线

  protected  int x1;

  protected  int y1;

  protected  int x2;

  protected  int y2;
  protected transient boolean isChoosed;
  private int[] RGB;
 
public Entity(int id, Color color, int width, int style, int x1, int y1, int x2,
		int y2) {
	super();
	this.id = id;
	this.color = color;
	this.width = width;
	this.style = style;
	this.x1 = x1;
	this.y1 = y1;
	this.x2 = x2;
	this.y2 = y2;
	isChoosed = false;
	RGB = new int[3];
	if(color !=null){
	RGB[0] = color.getRed();
	RGB[1] = color.getGreen();
	RGB[2] = color.getBlue();
	}
}
	public abstract void draw(Display display,GC gc) ;
	
	public  String isFocused(int x , int y){
		int xmin =Math.min(x1, x2);
		int xmax = Math.max(x1, x2);
		int ymin = Math.min(y1, y2);
		int ymax = Math.max(y1, y2);
		x1 = xmin;
		y1 = ymin;
		x2 = xmax;
		y2 = ymax;
		return null;
	}
	  //被选中的要画4个圆圈来提供缩放
	  /*
	   * entity 表示鼠标进入元素范围内
	   * 然后分别可能有上，下，左，右，左上，右上，左下，右下，no
	   * 
	   */

	public void setChoosed(){
		isChoosed = true;
	}
	public void cancelChoosed(){
		isChoosed = false;
	  
	}
	public void changeDrawing(int x, int y){//传递一直不断变化的第二点信息回来
		x2 =x;
		y2 = y;
	}
	
	public void move(int xmove, int ymove) {
		x2 = x2+xmove;
		y2 = y2 + ymove;
	 	x1 = x1 +xmove;
	 	y1 = y1 +ymove;
	}

	public void changeSize(String type,  int xmove,int ymove) {
		this.isFocused(0, 0);
		if(type.equals("zoomleftup")){
			x1 = x1+xmove;
			y1 = y1 +ymove;
			return;
		}
		if(type.equals("zoomleftdown")){
			x1 = x1 +xmove;
			y2 = y2+ymove;
			return;
		}
		if(type.equals("zoomrightup")){
			x2 = x2 +xmove;
			y1 = y1 +ymove;
			return;
		}
		if(type.equals("zoomrightdown")){
			x2 = x2 +xmove;
			y2 = y2 +ymove;
			return;
		}
	//	this.isFocused(0, 0);//重置x1，y1与x2，y2
	}
	protected double distance(double x1,double y1 , double x2 ,double y2){
		return Math.sqrt(Math.pow( Math.abs(x1-x2),2) + Math.pow(Math.abs(y1 - y2),2));
	}

public int getId() {
	return id;
}

public void setId(int id) {
	this.id = id;
}

public Color getColor() {
	return color;
}

public void setColor(Color color) {
	this.color = color;
}

public int getWidth() {
	return width;
}
public void setWidth(int width) {
	this.width = width;
}
public int getStyle() {
	return style;
}
public void setStyle(int style) {
	this.style = style;
}
public int getX1() {
	return x1;
}
public void setX1(int x1) {
	this.x1 = x1;
}
public int getY1() {
	return y1;
}
public void setY1(int y1) {
	this.y1 = y1;
}
public int getX2() {
	return x2;
}
public void setX2(int x2) {
	this.x2 = x2;
}
public int getY2() {
	return y2;
}
public void setY2(int y2) {
	this.y2 = y2;
}
public void initeColor(){
	color = new Color(Display.getCurrent(),RGB[0],RGB[1],RGB[2]);
}

}